package com.shuang.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.shuang.mapper.DbGoodsDescribeMapper;
import com.shuang.pojo.DbGoodsDescribe;
import com.shuang.pojo.DbGoodsDescribeExample;
import com.shuang.pojo.DbGoodsDescribeExample.Criteria;
import com.shuang.service.DbGoodsDescribeService;
@Service("dbGoodsDescribeService")
public class DbGoodsDescribeServiceImpl implements DbGoodsDescribeService {

	@Resource(name="dbGoodsDescribeMapper")
	private DbGoodsDescribeMapper dbGoodsDescribeMapper;
	@Override
	public Map<String, Object> getDescribeInfoById(Long gId) {
		DbGoodsDescribeExample example = new DbGoodsDescribeExample();
		Criteria criteria = example.createCriteria();
		criteria.andGIdEqualTo(gId);
		List<DbGoodsDescribe> result = dbGoodsDescribeMapper.selectByExampleWithBLOBs(example);
		Map<String, Object> map=new HashMap<String, Object>();
		if(result!=null&&result.size()>0){
			map.put("status", 200);
			map.put("data", result.get(0));
		}else{
			map.put("status", 404);
			map.put("data", "沒有查到指定id的商品描述信息");
		}
		
		return map;
	}
	@Override
	public Map<String, Object> updateDescribeInfoById(
			DbGoodsDescribe dbGoodsDescribe) {
		dbGoodsDescribe.setDeUpdateTime(new Date());
		DbGoodsDescribeExample example = new DbGoodsDescribeExample();
		Criteria criteria = example.createCriteria();
		criteria.andGIdEqualTo(dbGoodsDescribe.getgId());
		int result = dbGoodsDescribeMapper.updateByExampleSelective(dbGoodsDescribe, example);
		Map<String, Object> map=new HashMap<String, Object>();
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 404);
		}
		return map;
	}

}
